<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="达人ID" prop="talentId">
        <el-input v-model.trim="queryParams.talentId" placeholder="请输入达人ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="达人昵称" prop="talentName">
        <el-input v-model.trim="queryParams.talentName" placeholder="请输入达人昵称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合作平台" prop="platform">
        <el-input v-model.trim="queryParams.platform" placeholder="请输入合作平台" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合同编号" prop="contractNumber">
        <el-input v-model.trim="queryParams.contractNumber" placeholder="请输入合同编号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'" size="mini"
          @click="shouqi">展开/收起</el-button>
      </el-form-item>
      <br>
      <el-form-item label="时间类型" prop="dateType">
        <el-radio-group v-model="queryParams.dateType" size="small">
          <el-radio-button v-for="(item, index) in typeArr" :key="index" :label="item.value">{{ item.label
          }}</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <div v-if="isOpen">
        <el-form-item label="合同名称" prop="contractName">
          <el-input v-model.trim="queryParams.contractName" placeholder="请输入合同名称" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="合作周期开始时间" prop="startDate">
          <el-date-picker clearable v-model="queryParams.startDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合作周期开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合作周期结束时间" prop="endDate">
          <el-date-picker clearable v-model="queryParams.endDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合作周期结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="成交GMV" prop="gmv">
          <el-input v-model.trim="queryParams.gmv" placeholder="请输入成交GMV" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="销售件数" prop="salesVolume">
          <el-input v-model.trim="queryParams.salesVolume" placeholder="请输入销售件数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="观看人数" prop="viewers">
          <el-input v-model.trim="queryParams.viewers" placeholder="请输入观看人数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="互动评论数" prop="interactionComments">
          <el-input v-model.trim="queryParams.interactionComments" placeholder="请输入互动评论数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="佣金率" prop="commissionRate">
          <el-input v-model.trim="queryParams.commissionRate" placeholder="请输入佣金率" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="合作坑位费" prop="slottingFee">
          <el-input v-model.trim="queryParams.slottingFee" placeholder="请输入合作坑位费" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="直播ROI" prop="liveRoi">
          <el-input v-model.trim="queryParams.liveRoi" placeholder="请输入直播ROI" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="图文阅读量" prop="imageReadCount">
          <el-input v-model.trim="queryParams.imageReadCount" placeholder="请输入图文阅读量" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="图文分享次数" prop="imageShares">
          <el-input v-model.trim="queryParams.imageShares" placeholder="请输入图文分享次数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="图文互动留言数" prop="imageInteractionComments">
          <el-input v-model.trim="queryParams.imageInteractionComments" placeholder="请输入图文互动留言数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="图文互动点赞数" prop="imageLikes">
          <el-input v-model.trim="queryParams.imageLikes" placeholder="请输入图文互动点赞数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="图文合作费用" prop="imageCooperationFee">
          <el-input v-model.trim="queryParams.imageCooperationFee" placeholder="请输入图文合作费用" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="图文ROI" prop="imageRoi">
          <el-input v-model.trim="queryParams.imageRoi" placeholder="请输入图文ROI" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="短视频全网播放量" prop="videoPlayCount">
          <el-input v-model.trim="queryParams.videoPlayCount" placeholder="请输入短视频全网播放量" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="短视频完播率" prop="completionRate">
          <el-input v-model.trim="queryParams.completionRate" placeholder="请输入短视频完播率" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="短视频互动留言数" prop="videoInteractionComments">
          <el-input v-model.trim="queryParams.videoInteractionComments" placeholder="请输入短视频互动留言数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="短视频互动点赞数" prop="videoLikes">
          <el-input v-model.trim="queryParams.videoLikes" placeholder="请输入短视频互动点赞数" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="短视频合作费用" prop="videoCooperationFee">
          <el-input v-model.trim="queryParams.videoCooperationFee" placeholder="请输入短视频合作费用" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="短视频ROI" prop="videoRoi">
          <el-input v-model.trim="queryParams.videoRoi" placeholder="请输入短视频ROI" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="逻辑删除" prop="isDelete">
          <el-input v-model.trim="queryParams.isDelete" placeholder="请输入逻辑删除" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['talent:BiTalentCooperativeEvaluation:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['talent:BiTalentCooperativeEvaluation:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['talent:BiTalentCooperativeEvaluation:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['talent:BiTalentCooperativeEvaluation:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table @row-dblclick="t" v-loading="loading" :data="BiTalentCooperativeEvaluationList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column width="120" prop="contractNumber" label="合同编号" align="center"
        :show-overflow-tooltip="true"></el-table-column>
      <el-table-column width="120" prop="talentId" label="达人ID" align="center"></el-table-column>
      <el-table-column width="120" prop="talentName" label="达人昵称" align="center"></el-table-column>
      <el-table-column width="120" prop="fans" label="粉丝数" align="center">

      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" width="120" prop="talentLabel" label="达人标签"
        align="center"></el-table-column>
      <!-- <el-table-column width="120" prop="cooperationType" label="合作方式" align="center"></el-table-column> -->
      <!-- <el-table-column width="120" prop="platform" label="合作平台" align="center"></el-table-column>
      <el-table-column width="120" prop="cooperationQuantity" label="合作场次" align="center"></el-table-column>
      <el-table-column width="120" prop="cooperationItemQuantity" label="合作商品款" align="center"></el-table-column>
      <el-table-column width="120" prop="gmv" label="累计销售GMV" align="center">

      </el-table-column>
      <el-table-column width="120" prop="netGMV" label="净销售GMV" align="center">

      </el-table-column>
      <el-table-column width="120" prop="salesVolume" label="销售件数" align="center"></el-table-column>
      <el-table-column width="120" prop="settledCommission" label="已结算佣金" align="center">

      </el-table-column>
      <el-table-column width="120" prop="promotionCost" label="合作推广费" align="center">

      </el-table-column>
      <el-table-column width="120" prop="dataDate" label="约定交付时间" align="center">

      </el-table-column> -->
      <el-table-column prop="graphicCount" label="合作图文数" align="center" />
      <el-table-column prop="totalInteraction" label="互动总量" align="center">

      </el-table-column>
      <el-table-column prop="totalClick" label="点击总量" align="center">

      </el-table-column>
      <el-table-column prop="totalComment" label="评论总量" align="center">

      </el-table-column>
      <el-table-column prop="avgClickRate" label="平均点击率" align="center">

      </el-table-column>
      <el-table-column width="300" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
            @click="handleTalentCooperativeEvaluation(scope.row)">查看评价</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleSettlement(scope.row)">合作结案</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog :visible.sync="openContract" append-to-body title="查看评价" width="1800px" v-if="openContract">
      <BiTalentCooperativeEvaluationindex :row="Evaluationrow" />
    </el-dialog>
    <!-- 添加或修改达人-合作结案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="达人昵称" prop="talentName">
          <el-input :disabled="true" v-model.trim="form.talentName" placeholder="请输入达人昵称" />
        </el-form-item>

        <!-- <el-form-item label="合同编号" prop="contractNumber">
              <el-select v-model="form.contractNumber" placeholder="请输入合同编号" clearable @change="changecontractNumber">
                <el-option v-for="dict in ContractNumberlist" :key="dict" :label="dict" :value="dict" />
              </el-select>
              <el-button type="primary" plain size="mini" @click="opentagkey = true">+</el-button>
            </el-form-item> -->

        <el-dialog :visible.sync="opentagkey" width="1800px" append-to-body v-if="opentagkey">
          <div class="el-dialog-div">
            <component :is="'BiTalentContractindex'" :contractNumber="form.contractNumber"
              @handleContract="handleContract" />
          </div>
        </el-dialog>

        <!-- <el-form-item label="合同名称" prop="contractName">
              <el-input v-model.trim="form.contractName" placeholder="请输入合同名称" />
            </el-form-item>
            <el-form-item label="合作周期" prop="dataDate">
             
              <el-date-picker v-model="value2" type="daterange" align="right" unlink-panels range-separator="-"
                start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="changeTime"
                size="mini">
              </el-date-picker>
            </el-form-item> -->

        <el-form-item label="合作图文数" prop="graphicCount">
          <el-input-number v-model="form.graphicCount" :min="0" :precision="0" controls-position="right"
            placeholder="请输入合作图文数" />
        </el-form-item>

        <el-form-item label="互动总量" prop="totalInteraction">
          <el-input v-model.number="form.totalInteraction" type="number" min="0" placeholder="请输入互动总量"
            oninput="value=value.replace(/[^\d]/g,'')" />
        </el-form-item>

        <el-form-item label="点击总量" prop="totalClick">
          <el-input v-model.number="form.totalClick" type="number" min="0" placeholder="请输入点击总量"
            oninput="value=value.replace(/[^\d]/g,'')" />
        </el-form-item>

        <el-form-item label="评论总量" prop="totalComment">
          <el-input v-model.number="form.totalComment" type="number" min="0" placeholder="请输入评论总量"
            oninput="value=value.replace(/[^\d]/g,'')" />
        </el-form-item>

        <el-form-item label="平均点击率" prop="avgClickRate">
          <el-input v-model.number="form.avgClickRate" placeholder="请输入平均点击率">
            <template #append>%</template>
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  selectTalentCooperativeList,
  getBiTalentCooperativeEvaluation,
  delBiTalentCooperativeEvaluation,
  addBiTalentCooperativeEvaluation,
  updateBiTalentCooperativeEvaluation,
  selectContractNumberlist,
  selectTalentContract,
  selectDataSingle,
  updateCooperativeConclusion,
  selectCooperativeImageTextList
} from "@/api/talent/BiTalentCooperativeEvaluation";
import moment from "moment";
import BiTalentContractindex from "@/views/talent/BiTalentContract/BiTalentContractindex.vue";
import {
  removeContract,
  cooperativeSettlement
} from "@/api/talent/BiTalentContract";
import BiTalentCooperativeEvaluationindex from '@/views/talent/BiTalentCooperativeEvaluation/BiTalentCooperativeEvaluationindex.vue'

export default {
  name: "BiTalentCooperativeEvaluation",
  props: {
    row: {
      type: Object,
      default: () => { },
    },
  },
  components: {
    BiTalentContractindex,
    BiTalentCooperativeEvaluationindex
  },
  data() {
    return {
      openContract: false,
      Evaluationrow: {},


      typeArr: [

        { value: "近7天", label: "近7天" },
        { value: "近15天", label: "近15天" },
        { value: "近1个月", label: "近1个月" },
        { value: "近2个月", label: "近2个月" },
        { value: "近3个月", label: "近3个月" },
        // { value: "近1年", label: "近1年" },
      ],
      opentagkey: false,
      ContractNumberlist: [],
      isOpen: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 达人-合作结案表格数据
      BiTalentCooperativeEvaluationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        dateType: '近3个月',
        pageNum: 1,
        pageSize: 10,
        talentId: null,
        talentName: null,
        cooperationType: "img",
        platform: null,
        contractNumber: null,
        contractName: null,
        startDate: null,
        endDate: null,
        gmv: null,
        salesVolume: null,
        viewers: null,
        interactionComments: null,
        commissionRate: null,
        slottingFee: null,
        liveRoi: null,
        imageReadCount: null,
        imageShares: null,
        imageInteractionComments: null,
        imageLikes: null,
        imageCooperationFee: null,
        imageRoi: null,
        videoPlayCount: null,
        completionRate: null,
        videoInteractionComments: null,
        videoLikes: null,
        videoCooperationFee: null,
        videoRoi: null,
        isDelete: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      value2: [], // 默认选中最近30天
    };
  },
  created() {
    this.getList();
  },
  watch: {
    row: {
      handler: function (newnew, oldold) {
        let obj = {
          cooperationId: this.row.platformId,
          sourcePlatform: this.row.platform,
        };
        this.getselectContractNumberlist(obj);
        this.queryParams.talentId = this.row.platformId;
        this.getList();
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    handleTalentCooperativeEvaluation(row) {
      this.Evaluationrow = row
      this.openContract = true
    },
    handleContract(row) {
      this.form.contractNumber = row.contractNumber;
      this.form.contractName = row.contractName;
      this.value2 = [row.cooperationStartDate, row.cooperationEndDate];
      let m1 = moment(this.value2[0]).format("YYYY-MM-DD");
      let m2 = moment(this.value2[1]).format("YYYY-MM-DD");
      // console.log(JSON.stringify(m1));
      // console.log(JSON.stringify(m2));
      this.form.startDate = m1;
      this.form.endDate = m2;
      this.opentagkey = false;
    },
    changecontractNumber() {
      selectTalentContract({ contractNumber: this.form.contractNumber }).then(
        (response) => { }
      );
    },
    getselectContractNumberlist(obj) {
      selectContractNumberlist(obj).then((response) => {
        this.ContractNumberlist = response;
      });
    },
    changeTime() {
      // console.log(JSON.stringify(this.value2));
      let m1 = moment(this.value2[0]).format("YYYY-MM-DD");
      let m2 = moment(this.value2[1]).format("YYYY-MM-DD");
      // console.log(JSON.stringify(m1));
      // console.log(JSON.stringify(m2));
      this.form.startDate = m1;
      this.form.endDate = m2;
      // this.getList();
      // this.queryParams.startDate = m1;
      // this.queryParams.endDate = m2;
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询达人-合作结案列表 */
    getList() {
      this.loading = true;
      selectCooperativeImageTextList(this.queryParams).then((response) => {
        this.BiTalentCooperativeEvaluationList = response
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        talentId: null,
        talentName: null,
        cooperationType: null,
        platform: null,
        contractNumber: null,
        contractName: null,
        startDate: null,
        endDate: null,
        gmv: null,
        salesVolume: null,
        viewers: null,
        interactionComments: null,
        commissionRate: null,
        slottingFee: null,
        liveRoi: null,
        imageReadCount: null,
        imageShares: null,
        imageInteractionComments: null,
        imageLikes: null,
        imageCooperationFee: null,
        imageRoi: null,
        videoPlayCount: null,
        completionRate: null,
        videoInteractionComments: null,
        videoLikes: null,
        videoCooperationFee: null,
        videoRoi: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelete: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.queryParams.cooperationType = "img";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.talentId = this.row.platformId;
      this.form.talentName = this.row.xhsNickname;
      this.open = true;
      this.title = "添加达人-合作结案";
    },
    //点击某一行
    t(row, column, cell, event) {
      console.log(row, column, cell, event);

      this.handleUpdate(row);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      let id = { contractNumber: row.contractNumber }

      selectDataSingle(id).then((response) => {
        this.form = response
        this.value2 = [this.form.startDate, this.form.endDate];
        this.open = true;
        this.title = "修改达人-合作结案";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.cooperationType = "img";
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateCooperativeConclusion(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiTalentCooperativeEvaluation(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    handleSettlement(row) {
      const ids = { contractNumber: row.contractNumber }
      this.$modal
        .confirm('是否确认结案达人-合作结案的数据项？')
        .then(function () {
          return cooperativeSettlement(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("结案成功");
        })
        .catch(() => { });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = { contractNumber: row.contractNumber }
      this.$modal
        .confirm('是否确认删除达人-合作结案的数据项？')
        .then(function () {
          return removeContract(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "talent/BiTalentCooperativeEvaluation/export",
        {
          ...this.queryParams,
        },
        `BiTalentCooperativeEvaluation_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
